# Copyright © 2017 Intel Corporation
# SPDX-License-Identifier: MIT

subdir('program')
subdir('main')

# files shared between classic mesa and gallium mesa
files_libmesa = files(
  'main/accum.c',
  'main/accum.h',
  'main/api_arrayelt.c',
  'main/api_arrayelt.h',
  'main/arbprogram.c',
  'main/arrayobj.c',
  'main/arrayobj.h',
  'main/atifragshader.c',
  'main/atifragshader.h',
  'main/attrib.c',
  'main/attrib.h',
  'main/barrier.c',
  'main/bbox.c',
  'main/bbox.h',
  'main/blend.c',
  'main/blend.h',
  'main/blit.c',
  'main/blit.h',
  'main/bufferobj.c',
  'main/bufferobj.h',
  'main/buffers.c',
  'main/buffers.h',
  'main/clear.c',
  'main/clip.c',
  'main/clip.h',
  'main/colormac.h',
  'main/compute.c',
  'main/condrender.c',
  'main/condrender.h',
  'main/config.h',
  'main/conservativeraster.c',
  'main/conservativeraster.h',
  'main/context.c',
  'main/context.h',
  'main/copyimage.c',
  'main/dd.h',
  'main/debug.c',
  'main/debug.h',
  'main/debug_output.c',
  'main/debug_output.h',
  'main/depth.c',
  'main/depth.h',
  'main/dlist.c',
  'main/dlist.h',
  'main/draw.c',
  'main/draw.h',
  'main/draw_validate.c',
  'main/draw_validate.h',
  'main/drawpix.c',
  'main/drawtex.c',
  'main/enable.c',
  'main/enable.h',
  'main/enums.h',
  'main/errors.c',
  'main/errors.h',
  'main/es1_conversion.c',
  'main/eval.c',
  'main/eval.h',
  'main/extensions.c',
  'main/extensions.h',
  'main/extensions_table.c',
  'main/extensions_table.h',
  'main/externalobjects.c',
  'main/externalobjects.h',
  'main/fbobject.c',
  'main/fbobject.h',
  'main/feedback.c',
  'main/feedback.h',
  'main/ff_fragment_shader.c',
  'main/ffvertex_prog.c',
  'main/ffvertex_prog.h',
  'main/fog.c',
  'main/fog.h',
  'main/format_pack.h',
  'main/format_unpack.h',
  'main/format_utils.c',
  'main/format_utils.h',
  'main/formatquery.c',
  'main/formatquery.h',
  'main/formats.c',
  'main/formats.h',
  'main/framebuffer.c',
  'main/framebuffer.h',
  'main/genmipmap.c',
  'main/genmipmap.h',
  'main/get.c',
  'main/get.h',
  'main/getstring.c',
  'main/glformats.c',
  'main/glformats.h',
  'main/glspirv.c',
  'main/glspirv.h',
  'main/glthread.c',
  'main/glthread.h',
  'main/glthread_bufferobj.c',
  'main/glthread_draw.c',
  'main/glthread_draw_unroll.c',
  'main/glthread_get.c',
  'main/glthread_list.c',
  'main/glthread_marshal.h',
  'main/glthread_pixels.c',
  'main/glthread_shaderobj.c',
  'main/glthread_varray.c',
  'main/hash.c',
  'main/hash.h',
  'main/hint.c',
  'main/hint.h',
  'main/image.c',
  'main/image.h',
  'main/light.c',
  'main/light.h',
  'main/lines.c',
  'main/lines.h',
  'main/macros.h',
  'main/matrix.c',
  'main/matrix.h',
  'main/menums.h',
  'main/mesa_private.h',
  'main/mipmap.c',
  'main/mipmap.h',
  'main/mtypes.h',
  'main/multisample.c',
  'main/multisample.h',
  'main/objectlabel.c',
  'main/pack.c',
  'main/pack.h',
  'main/pbo.c',
  'main/pbo.h',
  'main/performance_monitor.c',
  'main/performance_monitor.h',
  'main/performance_query.c',
  'main/performance_query.h',
  'main/pipelineobj.c',
  'main/pipelineobj.h',
  'main/pixel.c',
  'main/pixel.h',
  'main/pixelstore.c',
  'main/pixelstore.h',
  'main/pixeltransfer.c',
  'main/pixeltransfer.h',
  'main/points.c',
  'main/points.h',
  'main/polygon.c',
  'main/polygon.h',
  'main/program_binary.c',
  'main/program_binary.h',
  'main/program_resource.c',
  'main/querymatrix.c',
  'main/queryobj.c',
  'main/queryobj.h',
  'main/rastpos.c',
  'main/rastpos.h',
  'main/readpix.c',
  'main/readpix.h',
  'main/renderbuffer.c',
  'main/renderbuffer.h',
  'main/robustness.c',
  'main/samplerobj.c',
  'main/samplerobj.h',
  'main/scissor.c',
  'main/scissor.h',
  'main/shader_query.cpp',
  'main/shaderapi.c',
  'main/shaderapi.h',
  'main/shaderimage.c',
  'main/shaderimage.h',
  'main/shaderobj.c',
  'main/shaderobj.h',
  'main/shared.c',
  'main/shared.h',
  'main/spirv_capabilities.c',
  'main/spirv_capabilities.h',
  'main/spirv_extensions.c',
  'main/spirv_extensions.h',
  'main/state.c',
  'main/state.h',
  'main/stencil.c',
  'main/stencil.h',
  'main/syncobj.c',
  'main/syncobj.h',
  'main/texcompress.c',
  'main/texcompress.h',
  'main/texcompress_astc.cpp',
  'main/texcompress_astc.h',
  'main/texcompress_bptc.c',
  'main/texcompress_bptc.h',
  'main/texcompress_cpal.c',
  'main/texcompress_cpal.h',
  'main/texcompress_etc.c',
  'main/texcompress_etc.h',
  'main/texcompress_fxt1.c',
  'main/texcompress_fxt1.h',
  'main/texcompress_rgtc.c',
  'main/texcompress_rgtc.h',
  'main/texcompress_s3tc.c',
  'main/texcompress_s3tc.h',
  'main/texenv.c',
  'main/texenvprogram.h',
  'main/texgen.c',
  'main/texgetimage.c',
  'main/texgetimage.h',
  'main/teximage.c',
  'main/teximage.h',
  'main/texobj.c',
  'main/texobj.h',
  'main/texparam.c',
  'main/texparam.h',
  'main/texstate.c',
  'main/texstate.h',
  'main/texstorage.c',
  'main/texstorage.h',
  'main/texstore.c',
  'main/texstore.h',
  'main/texturebindless.c',
  'main/texturebindless.h',
  'main/textureview.c',
  'main/textureview.h',
  'main/transformfeedback.c',
  'main/transformfeedback.h',
  'main/uniform_query.cpp',
  'main/uniforms.c',
  'main/uniforms.h',
  'main/varray.c',
  'main/varray.h',
  'main/vdpau.c',
  'main/version.c',
  'main/version.h',
  'main/viewport.c',
  'main/viewport.h',
  'main/es1_conversion.c',
  'math/m_eval.c',
  'math/m_eval.h',
  'math/m_matrix.c',
  'math/m_matrix.h',
  'program/arbprogparse.c',
  'program/arbprogparse.h',
  'program/prog_cache.c',
  'program/prog_cache.h',
  'program/prog_instruction.c',
  'program/prog_instruction.h',
  'program/prog_parameter.c',
  'program/prog_parameter.h',
  'program/prog_parameter_layout.c',
  'program/prog_parameter_layout.h',
  'program/prog_print.c',
  'program/prog_print.h',
  'program/prog_statevars.c',
  'program/prog_statevars.h',
  'program/prog_to_nir.c',
  'program/prog_to_nir.h',
  'program/program.c',
  'program/program.h',
  'program/program_parse_extra.c',
  'program/program_parser.h',
  'program/symbol_table.c',
  'program/symbol_table.h',
  'state_tracker/st_atifs_to_nir.c',
  'state_tracker/st_atifs_to_nir.h',
  'state_tracker/st_atom_array.cpp',
  'state_tracker/st_atom_atomicbuf.c',
  'state_tracker/st_atom_blend.c',
  'state_tracker/st_atom_clip.c',
  'state_tracker/st_atom_constbuf.c',
  'state_tracker/st_atom_constbuf.h',
  'state_tracker/st_atom_depth.c',
  'state_tracker/st_atom_framebuffer.c',
  'state_tracker/st_atom_image.c',
  'state_tracker/st_atom_list.h',
  'state_tracker/st_atom_msaa.c',
  'state_tracker/st_atom_pixeltransfer.c',
  'state_tracker/st_atom_rasterizer.c',
  'state_tracker/st_atom_sampler.c',
  'state_tracker/st_atom_scissor.c',
  'state_tracker/st_atom_shader.c',
  'state_tracker/st_atom_stipple.c',
  'state_tracker/st_atom_storagebuf.c',
  'state_tracker/st_atom_tess.c',
  'state_tracker/st_atom_texture.c',
  'state_tracker/st_atom_viewport.c',
  'state_tracker/st_bc1_tables.h',
  'state_tracker/st_cb_bitmap.c',
  'state_tracker/st_cb_bitmap.h',
  'state_tracker/st_cb_clear.c',
  'state_tracker/st_cb_clear.h',
  'state_tracker/st_cb_copyimage.c',
  'state_tracker/st_cb_copyimage.h',
  'state_tracker/st_cb_drawpixels.c',
  'state_tracker/st_cb_drawpixels.h',
  'state_tracker/st_cb_drawtex.c',
  'state_tracker/st_cb_drawtex.h',
  'state_tracker/st_cb_eglimage.c',
  'state_tracker/st_cb_eglimage.h',
  'state_tracker/st_cb_feedback.c',
  'state_tracker/st_cb_feedback.h',
  'state_tracker/st_cb_flush.c',
  'state_tracker/st_cb_flush.h',
  'state_tracker/st_cb_rasterpos.c',
  'state_tracker/st_cb_rasterpos.h',
  'state_tracker/st_cb_readpixels.c',
  'state_tracker/st_cb_readpixels.h',
  'state_tracker/st_cb_texture.c',
  'state_tracker/st_cb_texture.h',
  'state_tracker/st_context.c',
  'state_tracker/st_context.h',
  'state_tracker/st_copytex.c',
  'state_tracker/st_copytex.h',
  'state_tracker/st_debug.c',
  'state_tracker/st_debug.h',
  'state_tracker/st_draw.c',
  'state_tracker/st_draw.h',
  'state_tracker/st_draw_feedback.c',
  'state_tracker/st_draw_hw_select.c',
  'state_tracker/st_extensions.c',
  'state_tracker/st_extensions.h',
  'state_tracker/st_format.c',
  'state_tracker/st_format.h',
  'state_tracker/st_gen_mipmap.c',
  'state_tracker/st_gen_mipmap.h',
  'state_tracker/st_glsl_to_nir.cpp',
  'state_tracker/st_glsl_to_nir.h',
  'state_tracker/st_interop.c',
  'state_tracker/st_interop.h',
  'state_tracker/st_manager.c',
  'state_tracker/st_manager.h',
  'state_tracker/st_nir.h',
  'state_tracker/st_nir_builtins.c',
  'state_tracker/st_nir_lower_builtin.c',
  'state_tracker/st_nir_lower_fog.c',
  'state_tracker/st_nir_lower_position_invariant.c',
  'state_tracker/st_nir_lower_tex_src_plane.c',
  'state_tracker/st_nir_unlower_io_to_vars.c',
  'state_tracker/st_pbo.c',
  'state_tracker/st_pbo_compute.c',
  'state_tracker/st_pbo.h',
  'state_tracker/st_program.c',
  'state_tracker/st_program.h',
  'state_tracker/st_sampler_view.c',
  'state_tracker/st_sampler_view.h',
  'state_tracker/st_scissor.c',
  'state_tracker/st_scissor.h',
  'state_tracker/st_shader_cache.c',
  'state_tracker/st_shader_cache.h',
  'state_tracker/st_texcompress_compute.c',
  'state_tracker/st_texcompress_compute.h',
  'state_tracker/st_texture.c',
  'state_tracker/st_texture.h',
  'state_tracker/st_util.h',
  'state_tracker/st_vdpau.c',
  'state_tracker/st_vdpau.h',
  'vbo/vbo.h',
  'vbo/vbo_attrib.h',
  'vbo/vbo_attrib_tmp.h',
  'vbo/vbo_context.c',
  'vbo/vbo_exec.c',
  'vbo/vbo_exec.h',
  'vbo/vbo_exec_api.c',
  'vbo/vbo_exec_draw.c',
  'vbo/vbo_exec_eval.c',
  'vbo/vbo_minmax_index.c',
  'vbo/vbo_noop.c',
  'vbo/vbo_save.c',
  'vbo/vbo_save.h',
  'vbo/vbo_save_api.c',
  'vbo/vbo_save_draw.c',
  'vbo/vbo_save_loopback.c',
  'vbo/vbo_util.h',
)

inc_libmesa_asm = []
if with_asm_arch == 'x86'
  files_libmesa += files(
    'x86/assyntax.h',
  )
endif

format_fallback_c = custom_target(
  'format_fallback.c',
  input : ['main/format_fallback.py', 'main/formats.csv'],
  output : 'format_fallback.c',
  command : [prog_python, '@INPUT0@', '@INPUT1@', '@OUTPUT@'],
  depend_files : files('main/format_parser.py'),
)

get_hash_h = custom_target(
  'get_hash.h',
  input : ['main/get_hash_generator.py', gl_and_es_api_files],
  output : 'get_hash.h',
  command : [prog_python, '@INPUT0@', '-f', '@INPUT1@'],
  depend_files : files('main/get_hash_params.py'),
  capture : true,
)

foreach x : [['format_info.h', 'format_info.py']]
  files_libmesa += custom_target(
    x[0],
    input : ['main/@0@'.format(x[1]), 'main/formats.csv'],
    output : x[0],
    command : [prog_python, '@INPUT0@', '@INPUT1@'],
    depend_files : files('main/format_parser.py'),
    capture : true,
  )
endforeach

files_libmesa += [
  mesa_lex,
  program_parse_tab,
  main_api_exec_c,
  main_api_exec_decl_h,
  main_api_save_h,
  main_api_save_init_h,
  main_api_beginend_init_h,
  main_api_hw_select_init_h,
  main_enums_c,
  format_fallback_c,
  get_hash_h,
  main_marshal_generated_h,
  main_dispatch_h,
  ir_expression_operation_h,
  sha1_h,
  main_unmarshal_table_c,
] + main_marshal_generated_c

if with_sse41
  libmesa_sse41 = static_library(
    'mesa_sse41',
    files('main/sse_minmax.c'),
    c_args : [c_msvc_compat_args, sse41_args],
    include_directories : [inc_include, inc_src, inc_mapi, inc_mesa, inc_gallium, inc_gallium_aux],
    gnu_symbol_visibility : 'hidden',
  )
else
  libmesa_sse41 = []
endif

_mesa_windows_args = []
if with_platform_windows
  _mesa_windows_args += [
    '-D_GLAPI_NO_EXPORTS',
    '-D_GDI32_',    # prevent gl* being declared __declspec(dllimport) in MS headers
  ]
endif

libmesa = static_library(
  'mesa',
  files_libmesa,
  c_args : [c_msvc_compat_args, _mesa_windows_args],
  cpp_args : [cpp_msvc_compat_args, _mesa_windows_args],
  gnu_symbol_visibility : 'hidden',
  include_directories : [
    inc_include, inc_src, inc_mapi, inc_mesa, inc_gallium, inc_gallium_aux,
    inc_libmesa_asm, include_directories('main'),
  ],
  link_with : [libmesa_sse41],
  dependencies : [idep_libglsl, idep_nir, idep_vtn, dep_vdpau, idep_mesautil],
  build_by_default : false,
)
